﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;
namespace Server_NhaSach.DataAccess.LogicLayer
{
    public class NhanVienDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion
        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion
        #region "Khai báo các Method"
        public bool InsertNhanVien(NhanVienDTO NhanVien)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[7];
            par[0] = new SqlParameter("@MaNV", NhanVien.MaNV);
            par[1] = new SqlParameter("@HoTenNV", NhanVien.HoTenNV);
            par[2] = new SqlParameter("@SoDTNV", NhanVien.SoDTNV);
            par[3] = new SqlParameter("@NgaySinhNV", NhanVien.NgaySinh);
            par[4] = new SqlParameter("@DiaChiNV", NhanVien.DiaChiNV);
            par[5] = new SqlParameter("@CMNDNV", NhanVien.CMNDNV);
            par[6] = new SqlParameter("@ChucVu", NhanVien.ChucVu);
            try
            {
                helper.InsertQuery("sp_Insert_NhanVien", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdateNhanVien(NhanVienDTO NhanVien)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[7];
            par[0] = new SqlParameter("@MaNV", NhanVien.MaNV);
            par[1] = new SqlParameter("@HoTenNV", NhanVien.HoTenNV);
            par[2] = new SqlParameter("@SoDTNV", NhanVien.SoDTNV);
            par[3] = new SqlParameter("@NgaySinh", NhanVien.NgaySinh);
            par[4] = new SqlParameter("@DiaChiNV", NhanVien.DiaChiNV);
            par[5] = new SqlParameter("@CMNDNV", NhanVien.CMNDNV);
            par[6] = new SqlParameter("@ChucVu", NhanVien.ChucVu);
            try
            {
                helper.UpdateQuery("sp_Update_NhanVien", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeleteNhanVien(string maNV)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@maNV", maNV);
            try
            {
                helper.DeleteQuery("sp_Delete_NhanVien", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_NhanVien()
        {
            helper = new Helper();
            DataSet ds_NV = helper.SelectQuery("sp_LayDS_NhanVien");
            return ds_NV;
        }
        #endregion
    }
}